package com.zhangqiang.git.auth2secrity.project.demo.controller;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class DemoController {

    @RequestMapping("/oauth2/users/me")
    @ResponseBody
    public User profile() {
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

        return user;
    }

    @RequestMapping("/oauth2/demo")
    @ResponseBody
    public String demo() {

        return "无需验证直接访问，说明拦截参数配置生效了";
    }
}
